package com.intct.hbase;

import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

/**
 * @author gufg
 * @since 2025-11-03 09:46
 */
public class HBaseConnection {
    public static Connection connection = null;

    // 内部静态代码(执行时机是类型加载时)
    static {
        try {
            connection = ConnectionFactory.createConnection();
            System.out.println("连接成功！");
        } catch (IOException e) {
            System.out.println("连接失败！");
            e.printStackTrace();
        }
    }
//
//    public static void main(String[] args) throws IOException {
////        Configuration config = new Configuration();
////        config.set("hbase.zookeeper.quorum", "cdh-node:2181");
//
//        Connection connection = null;
//
//        try {
//            connection = ConnectionFactory.createConnection();
//            System.out.println("连接成功！");
//        } catch (IOException e) {
//            System.out.println("连接失败！");
//            e.printStackTrace();
//        } finally {
//            if (connection != null) {
//                connection.close();
//            }
//        }
//
//    }
}
